package br.com.rodolfo.timesheet.dao;

import java.util.Date;
import java.util.List;

import javax.persistence.Query;

import org.springframework.stereotype.Repository;

import br.com.rodolfo.timesheet.entity.Pessoa;
import br.com.rodolfo.timesheet.entity.Ponto;

@Repository("pontoDAO")
public class PontoDAO extends GenericDAOImpl{
	
	
	
	@SuppressWarnings("unchecked")
	public List<Ponto> findPorPeriodo(Pessoa pessoa, Date dtInicial, Date dtFinal)
		throws Exception{
		
		StringBuilder sQuery = new StringBuilder("Select pb from Ponto pb where ");
		sQuery.append("pb.pessoa = :pessoabean and ");
		sQuery.append("pb.dia between :dataini and :datafim ");
	    sQuery.append("order by pb.dia");
	    
	    Query query = entityManager.createQuery(sQuery.toString());
	    query.setParameter("dataini", dtInicial);
	    query.setParameter("datafim", dtFinal);
	    query.setParameter("pessoabean", pessoa);
	    
	    return (List<Ponto>) query.getResultList();
		
	}
	

}
